#ifndef LOBBYSTATE_H_
#define LOBBYSTATE_H_

#include "MenuState.h"
#include "Server.h"
#include "Client.h"
#include "Players.h"
#include "Block.h"
#include "Text.h"
#include <vector>

class TextArea;

class LobbyState : public MenuState
{
public:
    LobbyState(unsigned int clientsToWaitFor, double wellSizeFactor);
    virtual ~LobbyState();

    virtual void init();

    GameState* handleClientConnectEvent(int playerId, const std::string& playerName);
    GameState* handleClientDisconnectedEvent(int playerId);
    GameState* handleServerGameStartEvent(unsigned int widthOfWell);
    GameState* handleClientReadyToPlayEvent(int playerId);

    virtual GameState* performMenuAction1();
    virtual GameState* performMenuAction2();
    virtual GameState* performMenuActionEscape();

    virtual GameState* handleEvent(const Event& event);

protected:
    virtual void addMenuLines();

private:
    void updateText();
    bool okToStartGame();
    void updatePlayerTexts();
    void sendPlayerUpdates();
    void addPlayerNameLines();

    ServerPtr server;
    ClientPtr client;
    PlayersPtr players;

    unsigned int clientsToWaitFor;
    Text* info;
    std::vector<Text*> playerTexts;
    std::vector<Block*> playerBlocks;
    double wellSizeFactor;
    bool isReady;
};

#endif
